<template>
	<view class="diyTask">
		<!-- 顶部搜索 -->
		<diySearch :type="true" :value='value'></diySearch>
		<!-- 搜索历史 -->
		<view class="history">
			<text class="text">搜索历史</text>
			<text class="iconfont icon-shanchu" @click="historyDeletes"></text>
		</view>
		<view class="history-body">
			<view class="history-item" v-for="(item,index) in historyList" :key="index" @click="value = item.name">
				{{item.name}}
			</view>
		</view>
		<diyTask :taskSwitch = 'false' :listJudge='true' :heightJudge="false"></diyTask>
	</view>
</template>

<script>
	import diySearch from '../../component/diy-search/diy-search.vue'
	import diyTask from '../../component/diy-task/diy-task.vue'
	export default{
		components:{
			diyTask,
			diySearch
		},
		data(){
			return {
				historyList:[],
				value:''
			}
		},
		onLoad(option){
		},
		onShow(){
			this.getData();
		},
		methods:{
			// 删除历史
			historyDeletes(){
				this.$http.sendrequest('/task/SearchDelete',{},{
					tokenJudge:true,
				}).then(res=>{
					if(res.code == 1){
						uni.showToast({title:res.msg,icon:'none'})
						this.getData();
					}
				})
			},
			//获取历史搜索
			getData(){
				this.$http.sendrequest('/task/SearchList',{},{
					tokenJudge:true,
				}).then(res=>{
					if(res.code == 1){
						this.historyList = res.data;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.diyTask{
		width: 100%;
		height: 100vh;
		background: #f7f7f7;
		.history{
			margin: 20rpx 30rpx 16rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.text{
				font-size: 16px;
				font-family: SourceHanSansSC-medium;
				font-weight: bold;
			}
			.iconfont{
				font-size: 34rpx;
				color: #333333;
			}
		}
		.history-body{
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			margin: 0 30rpx;
			.history-item{
				padding: 8rpx 10rpx;
				background: #EFF2F7;
				font-size: 26rpx;
				margin:0 14rpx 14rpx 0;
			}
		}
	}
</style>
